/*
* jlb
*/
package com.jlb.star.ctrl;

import com.alibaba.fastjson.JSON;
import com.jlb.core.entity.BeanRet;
import com.jlb.core.entity.Page;
import com.jlb.core.tools.redis.RedisUtils;
import com.jlb.star.entity.StarLevel;
import com.jlb.star.service.StarLevelSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 星级 控制器
 *
 * @author jlb
 */
@RestController
@RequestMapping("/starLevel")
@Slf4j
@Api(value = "星级控制器", description = "星级控制器")
public class StarLevelCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private StarLevelSV starLevelSV;

    /**
     * 查询StarLevel一个详情信息
     *
     * @param id
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询StarLevel一个详情信息", notes = "查询StarLevel一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(java.lang.Long id, java.lang.String code) {
        if (id == null) {
            return null;
        }
        if (code == null) {
            return null;
        }
        StarLevel starLevelObj = starLevelSV.load(id, code);
        log.info(JSON.toJSONString(starLevelObj));
        return BeanRet.create(true, "查询成功", starLevelObj);
    }


    /**
     * 根据条件id查询StarLevel一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询StarLevel一个详情信息", notes = "查询StarLevel一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if (id == null) {
            return null;
        }
        StarLevel starLevelObj = starLevelSV.loadById(id);
        log.info(JSON.toJSONString(starLevelObj));
        return BeanRet.create(true, "查询成功", starLevelObj);
    }

    /**
     * 根据条件code查询StarLevel一个详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询StarLevel一个详情信息", notes = "查询StarLevel一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public BeanRet loadByCode(@PathVariable java.lang.String code) {
        if (code == null) {
            return null;
        }
        StarLevel starLevelObj = starLevelSV.loadByCode(code);
        log.info(JSON.toJSONString(starLevelObj));
        return BeanRet.create(true, "查询成功", starLevelObj);
    }


    /**
     * 查询StarLevel信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询StarLevel信息集合", notes = "查询StarLevel信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore StarLevel starLevelObj, Integer curPage, Integer pageSize) {
        Page<StarLevel> page = new Page<StarLevel>(pageSize, curPage);
        List<StarLevel> starLevelObjs = starLevelSV.list(starLevelObj, page.genRowStart(), page.getPageSize());
        page.setVoList(starLevelObjs);
        int total = starLevelSV.count(starLevelObj);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);

    }


    /**
     * 查询StarLevel信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询StarLevel信息集合", notes = "查询StarLevel信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(java.lang.Long id, java.lang.String code, Integer curPage, Integer pageSize) {
        Page<StarLevel> page = new Page<StarLevel>(pageSize, curPage);
        List<StarLevel> starLevelObjs = starLevelSV.list(id, code, page.genRowStart(), page.getPageSize());
        page.setVoList(starLevelObjs);
        int total = starLevelSV.count(id, code);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 统计StarLevel信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计StarLevel信息数量根据主键", notes = " 统计StarLevel信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id, java.lang.String code) {
        return starLevelSV.count(id, code);
    }

    /**
     * 统计StarLevel信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计StarLevel信息数量", notes = "统计StarLevel信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "deposit", value = "升级押金", paramType = "query"),
            @ApiImplicitParam(name = "starLevel", value = "星级", paramType = "query"),
            @ApiImplicitParam(name = "multiple", value = "动态收益上限倍数", paramType = "query"),
            @ApiImplicitParam(name = "withdrawCashRate", value = "金兰宝提现释放比例", paramType = "query")
    })
    @GetMapping(value = "/count")
    @ResponseBody
    public Integer count(@ApiIgnore StarLevel starLevelObj) {
        if (starLevelObj == null) {
            return starLevelSV.count(new HashMap());
        } else {
            return starLevelSV.count(starLevelObj);
        }
    }


    /**
     * 创建StarLevel
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建StarLevel", notes = "创建StarLevel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deposit", value = "升级押金", paramType = "query"),
            @ApiImplicitParam(name = "starLevel", value = "星级", paramType = "query"),
            @ApiImplicitParam(name = "multiple", value = "动态收益上限倍数", paramType = "query"),
            @ApiImplicitParam(name = "withdrawCashRate", value = "金兰宝提现释放比例", paramType = "query"),
            @ApiImplicitParam(name = "oreRefiningRate", value = "矿石提炼比例", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore StarLevel starLevelObj) {
        starLevelSV.save(starLevelObj);
        return BeanRet.create(true, "创建成功", starLevelObj);
    }


    /**
     * 修改StarLevel
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改StarLevel", notes = "修改StarLevel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "deposit", value = "升级押金", paramType = "query"),
            @ApiImplicitParam(name = "starLevel", value = "星级", paramType = "query"),
            @ApiImplicitParam(name = "multiple", value = "动态收益上限倍数", paramType = "query"),
            @ApiImplicitParam(name = "withdrawCashRate", value = "金兰宝提现释放比例", paramType = "query"),
            @ApiImplicitParam(name = "oreRefiningRate", value = "矿石提炼比例", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore StarLevel starLevelObj) {
        starLevelSV.modify(starLevelObj);
        return BeanRet.create(true, "修改成功", starLevelObj);
    }

    /**
     * 删除StarLevel
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除StarLevel", notes = "删除StarLevel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id, java.lang.String code) {
        starLevelSV.delete(id, code);
        return BeanRet.create(true, "删除StarLevel成功");
    }

}
